//
//  AddBackViewCell.m
//  QRMaster
//
//  Created by myApple on 16/6/3.
//  Copyright © 2016年 myApple. All rights reserved.
//

#import "AddBackViewCell.h"

@interface AddBackViewCell()

@property(nonatomic,strong)UIImageView * titleImgView;

@property(nonatomic,strong)UILabel * titleLabel;

@property(nonatomic,strong)UIView * lineView;

@end

@implementation AddBackViewCell

+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString * identityId = @"addBackViewCell";
    AddBackViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identityId];
    if (!cell) {
        cell = [[AddBackViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identityId];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self addAllSubView];
    }
    return self;
}

-(void)addAllSubView
{
    [self.contentView addSubview:self.titleImgView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.lineView];
}

#pragma mark - init
-(void)setTitle:(NSString *)title
{
    _title = title;
    self.titleLabel.text = title;
}

-(void)setImageNameString:(NSString *)imageNameString
{
    _imageNameString = imageNameString;
    self.titleImgView.image = [UIImage imageNamed:_imageNameString];
}

-(void)layoutSubviews
{
    CGFloat x = 22;
    CGFloat y = (self.frame.size.height - 18)/2.0;
    CGFloat width = 16;
    CGFloat height = 18;
    if (_indexRow != 0) {
        height = 14;
        y = (self.frame.size.height - 14)/2.0;
    }
    self.titleImgView.frame = CGRectMake(x, y, width, height);
    
    x += width + 10;
    y = (self.frame.size.height - 20)/2.0;
    width = self.frame.size.width - x - 16;
    height = 20;
    self.titleLabel.frame = CGRectMake(x, y, width, height);
    
    x = 16;
    width = self.frame.size.width - 2 * x;
    height = 0.5;
    y = self.frame.size.height;
    self.lineView.frame = CGRectMake(x, y, width, height);
}

-(UIImageView *)titleImgView
{
    if (!_titleImgView) {
        _titleImgView = [[UIImageView alloc]init];
    }
    return _titleImgView;
}

-(UILabel*)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.font = [UIFont systemFontOfSize:15.0];
        _titleLabel.textColor = UIColorFromRGB(0xffffff);
    }
    return _titleLabel;
}

-(UIView *)lineView
{
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = UIColorFromRGB(0xffffff);
    }
    return _lineView;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
